﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace MartinCarolan.EventSpy.UI
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow(EventSpy eventSpy)
        {
            DataContext = eventSpy;
            InitializeComponent();
        }

        private void CollectionViewSource_Filter(object sender, FilterEventArgs e)
        {
            var ev = e.Item as Event;
            var eventRegistrationEntry = EventSpy.Registry[ev.Source].FirstOrDefault(entry => entry.Event.Name == ev.Name);
            e.Accepted = eventRegistrationEntry.ShowInGrid;
        }

        private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            var eventsSource = Resources["eventsSource"] as CollectionViewSource;
            eventsSource.View.Refresh();
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = true;
        }
    }
}
